package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class ConfigActivity extends AppCompatActivity {
    private static final String TAG="Rate";
    private EditText dollarText;
    private EditText euroText;
    private EditText wonText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config);
        //接收参数
       Intent intent=getIntent();
       float dollar2=intent.getFloatExtra("dollar_rate_key",1.1f);
        float euro2=intent.getFloatExtra("euro_rate_key",2.2f);
        float won2=intent.getFloatExtra("won_rate_key",3.3f);
        Log.i(TAG,"onCreate:dollar2:"+dollar2);
        Log.i(TAG,"onCreate:euro2:"+euro2);
        Log.i(TAG,"onCreate:won2:"+won2);
        dollarText=findViewById(R.id.edit_dollar);
        euroText=findViewById(R.id.edit_euro);
        wonText=findViewById(R.id.edit_won);
        dollarText.setText(String.valueOf(dollar2));
        euroText.setText(String.valueOf(euro2));
        wonText.setText(String.valueOf(won2));
    }
    public void save(View btn){
        Log.i(TAG,"save:");
        //重新获取输入值
        String dollarStr=dollarText.getText().toString();
        String euroStr=euroText.getText().toString();
        String wonStr=wonText.getText().toString();
        Log.i(TAG,"save:dollarStr="+dollarStr);
        Log.i(TAG,"save:euroStr="+euroStr);
        Log.i(TAG,"save:wonStr="+wonStr);
        Intent intent=getIntent();
        //输入数据到Intent
        Bundle bundle=new Bundle();
        bundle.putFloat("key_dollar2",Float.parseFloat(dollarStr));
        bundle.putFloat("key_euro2",Float.parseFloat(euroStr));
        bundle.putFloat("key_won2",Float.parseFloat(wonStr));
        setResult(6,intent);
        finish();
    }
}